package com.bds.btcdc.adapter.huobi.market.http;

import com.alibaba.fastjson.JSONObject;
import com.bds.btcdc.model.CoinPairExchanges;
import com.bds.btcdc.api.model.Result;
import com.bds.btcdc.util.Const;
import com.bds.btcdc.util.SpringContextHolder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.messaging.simp.stomp.StompSession;

import java.util.List;

public class HuobiTask extends Thread {
	private Logger logger = LoggerFactory.getLogger(getClass());

	private HuobiService service = SpringContextHolder.getBean(HuobiService.class);

	private StompSession session;
	private List<CoinPairExchanges> pairs;
	public HuobiTask(StompSession session,List<CoinPairExchanges> pairs) {
		this.session = session;
		this.pairs=pairs;
	}

	public void huobiTask() {
		Result data = service.getMarketInfo(pairs);
		if (data != null) {
			if (session != null) {
				synchronized (session) {
					session.send(Const.HUOBI.MARKET_TOPIC, JSONObject.toJSONString(data).getBytes());
				}
			}

		}
	}

	@Override
	public synchronized void run() {
		this.huobiTask();
	}

}
